<template>
  <div class="app-container">
    <el-form
      ref="listFilterRef"
      :model="list.filter"
      inline
      class="list-filter"
    >
      <el-form-item prop="name">
        <el-input
          v-model="list.filter.name"
          placeholder="请输入名称搜索"
          clearable
        />
      </el-form-item>
      <el-form-item prop="status">
        <Status v-model="list.filter.status" />
      </el-form-item>
      <el-form-item>
        <el-button @click="reset">重置</el-button>
      </el-form-item>
    </el-form>

    <div class="table-operation">
      <auth-button @click="c" name="新增" />
      <el-pagination
        v-bind="elPaginationProps"
        :total="list.total"
        :currentPage.sync="list.filter.pageNo"
        :pageSize.sync="list.filter.pageSize"
      />
    </div>

    <el-table v-loading="list.loading" :data="list.data" v-bind="tableProp">
      <el-table-column label="名称" prop="name" />
      <el-table-column label="排序" prop="sort" />
      <el-table-column label="启用状态" width="80" align="center">
        <template slot-scope="{ row: { id, status } }">
          <KiPopSwitch
            v-bind="popSwitchProps(status)"
            @change="updateStatus({ id, status: status ^ 1 })"
          />
        </template>
      </el-table-column>
      <el-table-column label="操作" class-name="small-padding">
        <template slot-scope="{ row }">
          <auth-button @click="u({ id: row.id })" name="编辑" />
          <auth-button @click="d({ id: row.id })" name="删除" />
        </template>
      </el-table-column>
    </el-table>

    <KiFormDialog
      :show.sync="form.show"
      :title="formTitle"
      v-model="form.data"
      :submit="submitForm"
      :readonly="form.status === 'r'"
      width="70%"
      ref="formRef"
      :loading="form.loading"
    >
      <template #el-form>
        <el-form-item label="名称" prop="name" :verify="{ maxLength: 5 }">
          <el-input
            v-model="form.data.name"
            placeholder="请输入名称"
            maxlength="5"
            show-word-limit
          />
        </el-form-item>
        <el-form-item label="排序" prop="sort" verify>
          <Sort v-model="form.data.sort" />
        </el-form-item>

        <el-form-item label="所属地区" prop="areaCode" verify>
          <RegionSelect
            v-model="form.data.areaCode"
          />
        </el-form-item>

        <el-form-item label="关联景区" prop="corlorLineSaveAllDtos" verify>
          <ScenicSpot
            v-if="form.show"
            v-model="form.data.corlorLineSaveAllDtos"
          />
        </el-form-item>
      </template>
    </KiFormDialog>
  </div>
</template>

<script>
import pageMixin from '@/utils/pageMixin'
import useAdmateAdapter from '@/utils/useAdmateAdapter'
import ScenicSpot from '@/components/ScenicSpot'

// <el-tab-pane label="多彩贵州" name="1"></el-tab-pane>
// <el-tab-pane label="热门景区" name="2"></el-tab-pane>
export default {
  mixins: [pageMixin],
  components: { ScenicSpot },
  setup: () =>
    useAdmateAdapter({
      urlPrefix: 'one-travel-api/corlorLine',
      axiosConfig: {
        c: {
          url: 'saveScenic'
        },
        u: {
          url: 'saveScenic'
        }
      },
      list: {
        filter: {
          mainType: '2'
        }
      },
      form: {
        data: {
          mainType: '2'
        }
      }
    })
}
</script>
